/*
 *  Copyright 2007-2008 by Matthias Buch-Kromann <mbk.isv@cbs.dk>.
 *  *
 *  This file is part of the Open-source Dependency Toolkit (OSDT),
 *  see http://code.google.com/p/open-source-dependency-toolkit.
 *  
 *  The OSDT is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published
 *  by the Free Software Foundation, either version 3 of the License,
 *  or (at your option) any later version.
 * 
 *  The OSDT is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with the OSDT in the file COPYING and COPYING.LESSER. If not, see
 *  http://www.gnu.org/licenses.
 */

package org.osdtsystem.values;

import java.util.ArrayList;
import java.util.List;
import org.osdtsystem.utils.Helper;

/**
 * An augmentation maps a location name (string) and a feature into
 * an arbitrary feature value. 
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class Augmentation {
    private List<AugmentationEntry> augmentations = new ArrayList<AugmentationEntry>();
    private boolean given = false;

    public Augmentation() {
    }
    
    public void add(String node, String feature, Object value) {
        AugmentationEntry entry = new AugmentationEntry(node, feature, value);
        entry.setGiven(given);
        augmentations.add(entry);
    }
    
    public void rename(String oldNode, String oldFeature, String newNode, String newFeature) {
        for (AugmentationEntry entry : augmentations) {
            if ((oldNode == null || entry.node().equals(oldNode)) 
                    && (oldFeature == null || entry.node().equals(oldFeature))) {
                // Entry matches: change node and feature name, if new name is non-null
                if (newNode != null) 
                    entry.setNode(newNode);
                if (newFeature != null)
                    entry.setFeature(newFeature);
            }
        }
    }
    
    public void setGiven(boolean given) {
        this.given = given;
    }

    @Override
    public String toString() {
        return "{" + Helper.join(", ", augmentations) + "}";
    }
}
